﻿namespace LxBasic
{
    public struct MinMaxRange
    {
        public double Min;
        public double Max;
        public static MinMaxRange Empty => new MinMaxRange();
        public MinMaxRange()
        {
            Max = double.NegativeInfinity;
            Min = double.PositiveInfinity;
        }
        public MinMaxRange(double start)
        {
            Min = Max = start;
        }
        public void Include(MinMaxRange mm)
        {
            if (mm.Min < Min) Min = mm.Min;
            if (mm.Max > Max) Max = mm.Max;
        }
        public void Include(double d)
        {
            if (d < Min) Min = d;
            if (d > Max) Max = d;
        }
        public void IncludeHalf(double d)
        {
            if (d < Min) Min = d;
            else if (d > Max) Max = d;
        }
        public double GetRange()
        {
            return Max - Min;
        }
        public bool IsEmpty()
        {
            var e = Empty;
            return Min == e.Min && Max == e.Max;
        }
        public override string ToString()
        {
            return string.Format($"[{Min},{Max}]");
        }
    }
}
